Remixing [@Oliver Matthews' answer]1. I made it work recursively but instead using a wikilink-like syntax ![[filepath]]
that gets replaced with filepath.md
content
Create the script parseMd
#!/usr/bin/env bash
perl -ne 's#^!\[\[(.+?)\]\].*#`'$0' "$1.md"`#e;print' "$@"
chmod +x parseMd
To embed path/filename.md
use the syntax ![[path/filename]]
Now parse the main file
./parseMd main.md > result.md
To export directly to pdf, using pandoc
pandoc <(./parseMd main.md) -o result.pdf --pdf-engine wkhtmltopdf \
--css styles.css \
-V margin-top=11mm \
-V margin-bottom=11mm \
-V margin-left=11mm \
-V margin-right=11mm
More info on using pandoc to Export Markdown to PDF